//***********************************************************************************
// Function to apply level 3 rule set. 

// Author: Aravindh U095232L

//***********************************************************************************

function level_3_rules()
{
	//distribution function
	global_distribution();
}

// Function to compress all level2 NPC data to level3.
function level_3_compress (curr_grid) 
{
	var NPC = curr_grid.getNPCs();
	var army = NPC.Army;
	var rebel = NPC.Rebel;
	var citizen = NPC.Citizen;
	var spy = NPC.Spy;
	var merchant = NPC.Merchant;	

	if(army)
		for(var i =0;i<army.length;i++)
		{	
			for(var j=0;j<army[i].eventOutcomeQueue.length;j++)
			{
				if (army[i].eventOutcomeQueue[j]=="won")
				{
					army_fight++;
					rebel--;
					rebel_weapons-=1;
				}
				else if(isNaN(army[i].eventOutcomeQueue[j])==false)
				{
					army_weapons+=army[i].eventOutcomeQueue[j];
				}
				//console.log("army "+army[i].eventOutcomeQueue[j]);
			}
		}
	else if(rebel)
		for(var i =0;i<rebel.length;i++)
		{	
			for(var j=0;j<rebel[i].eventOutcomeQueue.length;j++)
			{
				if (rebel[i].eventOutcomeQueue[j]=="won")
				{
					rebel_fight++;
					army--;
					army_weapons-=1;
				}
				else if(isNaN(rebel[i].eventOutcomeQueue[j])==false)
				{
					//console.log("rebel "+rebel[i].eventOutcomeQueue[j]);
					rebel_weapons+=rebel[i].eventOutcomeQueue[j];
				}
			}
		}
	else if(citizen)
		for(var i =0;i<citizen.length;i++)
		{	
			if(citizen[i].rateAtWhichCanBeInfluenced<0.5)
				against_war++;
			else if(citizen[i].rateAtWhichCanBeInfluenced==0.5)
			{
				if(Math.random()<0.3)
					against_war--;
				else(Math.random()>0.7)
					for_war--;
			}
			else	
				for_war++;

			//console.log("citizen "+citizen[i].rateAtWhichCanBeInfluenced);
		}

}